fix: trim trailing whitespace from lhs when rhs wraps to new line#6881
fix: trim trailing whitespace from lhs when rhs wraps to new line#6881jlizen wants to merge 4 commits intorust-lang:mainfrom
Conversation
|
Previously we tried to address this in #5708, which took a more targeted approach and tried to update all the visibility formatting call sites instead of just conditionally checking the output of |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
Thanks for the backlinks! Sorry to miss the other issue... I tried to search x.x It looks like there was a consensus on approach in 5708. Let me see how bad it is to freshen that up. I do agree that this feels like a bugfix rather than something cutting across a version/>=2027 style boundary... As a user, I see rustfmt adding in trailing spaces itself, which I can't control and are clearly incorrect. We just need to be careful not to fix it in a way that has unwanted side effects. Glad to add in a gate though if needed. |
format_visibility returned e.g. "pub(crate) " with a trailing space. Every call site either relied on this space as a separator or (in format_header) explicitly trimmed it off. Remove the trailing space from format_visibility and add it explicitly at each call site. No change in formatted output. This fixes the root cause of rust-lang#6880: tuple struct field prefixes no longer carry a trailing space into rewrite_assign_rhs, so wrapping the type to the next line can no longer leave trailing whitespace.
fea9a7c to
33ad64a
Compare
Covers trailing whitespace on tuple struct fields with parenthesized visibility qualifiers (pub(crate), pub(super), pub(in path)) when the type wraps to the next line. Also includes pub with wrapping, named struct fields, and a short tuple field as controls. Fixes rust-lang#5703 Fixes rust-lang#6880
Covers the double space between pub and extern "C" in tuple struct fields when arguments wrap to multiple lines. Fixes rust-lang#5525
Covers the double space between pub and type in a newtype when an attribute is followed by a comment. Fixes rust-lang#5997
33ad64a to
0742c12
Compare
|
I switched over to the approach from #5708 (removing the trailing space from @rustbot ready |
Fixes #6880, #5703 , #5525, #5997
rewrite_assign_rhs_withjoinslhs + rhs. When the rhs wraps to a new line, trailing whitespace on the lhs (fromformat_visibilityreturning e.g."pub(crate) ") gets left behind. The fix trims trailing whitespace from lhs when rhs starts with\n. Same fix applied torewrite_assign_rhs_with_comments.Every other caller passes an lhs ending in
=or:, so the trim is a no-op outside the tuple struct field case.Regression test covers all three parenthesized visibility qualifiers (
pub(crate),pub(super),pub(in path)) on tuple struct fields with long types, pluspuband named struct fields as controls. Previously these tests failed before the fix due to trailing white space. (I couldn't figure out a good way to have an initial atomic commit showing the failure that still passed the test harness).